package com.hzx.service;

import com.hzx.OrderItem;
import com.hzx.User;
import com.hzx.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserService {

    @Autowired
    UserMapper userMapper;

    public int login(String name, String password) {
        Integer integer = userMapper.searchUser(name, password);
        return integer == null ? -1 : integer;
    }

    public boolean signUp(String name, String password) {
        User user = new User();
        user.setName(name);
        user.setPassword(password);
        try {
            userMapper.insert(user);
        } catch (Exception e) {
            return false;
        }
        return true;
    }

    public List<OrderItem> searchOrder(int uId) {
        return userMapper.searchOrder(uId);
    }
}
